package second50;


import org.junit.jupiter.api.Test;

public class T0067 {
    public String addBinary(String a, String b) {

        StringBuffer strb = new StringBuffer();

        int n = Math.max(a.length(), b.length());
        int carry = 0;
        for (int i = 0; i < n; i++) {
            if (i < a.length()) {
                carry += a.charAt(a.length() - i - 1) - '0';
            }
            if (i < b.length()) {
                carry += b.charAt(b.length() - i - 1) - '0';
            }
            strb.append(carry & 1 + '0');
            carry = carry / 2;
        }
        if (carry==1)strb.append('1');
        strb.reverse();
        return strb.toString();
    }
    @Test
    public void test() {
        System.out.println(addBinary("1","11"));
    }
}
